package cn.com.chenmin.data.service;

import cn.com.chenmin.data.entity.SamplePerson;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.vaadin.artur.helpers.CrudService;
import java.time.LocalDate;

@Service
public class SamplePersonService extends CrudService<SamplePerson, Integer> {

    private SamplePersonRepository repository;
    private final UserService userService;
    public SamplePersonService(@Autowired SamplePersonRepository repository, UserService userService) {
        this.repository = repository;
        this.userService = userService;
    }

    @Override
    protected SamplePersonRepository getRepository() {
        return repository;
    }

    @Override
    public SamplePerson update(SamplePerson entity) {
        entity.setUser(userService.get());
        return super.update(entity);
    }

    public SamplePerson get(){
        return repository.findByUser_Username(userService.getUsername());
    }

}
